package com.google.code.sip.ucenter.web.admin.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.google.code.sip.core.dao.Page;
import com.google.code.sip.core.utils.WebGridUtils;
import com.google.code.sip.ucenter.model.CreditLog;
import com.google.code.sip.ucenter.service.CreditLogManager;

@Controller
public class CreditLogController {

	@Autowired
	private CreditLogManager creditLogManager;

	@RequestMapping("/admin/creditLog!list.do")
	public ModelAndView list(HttpServletRequest request) {
		Map<String, Object> model = new HashMap<String, Object>();
		Page<CreditLog> page = new Page<CreditLog>();
		WebGridUtils.fillPage(request, page);
		// 查询条件
		String username = request.getParameter("username");
		String nickName = request.getParameter("nickName");
		if (StringUtils.isNotBlank(username)) {
			page.addFilter("username", username);
			model.put("username", username);
		}
		if (StringUtils.isNotBlank(nickName)) {
			page.addFilter("nickName", nickName);
			model.put("nickName", nickName);
		}
		creditLogManager.getAllCreditLogs(page);
		model.put("totalRows", (int) page.getTotalCount());
		model.put("page", page);
		return new ModelAndView("admin.creditLog.list", model);
	}
}
